package spreadsheet;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
 
 /**
  * 
  * @author Ahmed Saliem
  * this class is used to store a 2D-array of cells into xml document
  *
  */
public class XMLWriterDOM {
    
    public static Node getCell(Document doc,String cellRow, String cellCol, String cellType, String value) {
        Element cell = doc.createElement("SpreadSheetCell");
 
        //set cellType attribute
        cell.setAttribute("CellRow", cellRow);
        cell.setAttribute("CellCol", cellCol);
 
        //create CellType element
        cell.appendChild(getCellElements(doc, cell, "CellType", cellType));
 
        //create CellValue element
        cell.appendChild(getCellElements(doc, cell, "CellValue", value));
        

        return cell;
    }
 
 
    //utility method to create text node
    private static Node getCellElements(Document doc, Element element, String name, String value) {
        Element node = doc.createElement(name);
        node.appendChild(doc.createTextNode(value));
        return node;
    }
}
 